cannot create hex elf files with cmakelists - gcc

I am trying to use cmakelists to create a hex and elf file for my blinkled project, using IAR files.
The compilation is without errors with cmake but I dont see the files in the build folder.
my goal is to create a hex and elf files for flashing pursoses later on.
Can someone please tell me what I should modify to solve this problem?
thanks a lot
cmakelists:
cmake_minimum_required(VERSION 3.7.2)
######################################################################
#
# Project
#
######################################################################
project(blink_cortex_m0plus)
enable_language(ASM)
######################################################################
#
# CPP Definitions
#
######################################################################
set(PROJECT_FLAGS_ARCH
"-mcpu=cortex-m0plus \
-mthumb"
)
set(PROJECT_LINKER_FLAGS
"-Wl,-Map=${PROJECT_NAME}.map \
-L${PROJECT_SOURCE_DIR}/../config/ \
-Tlinker.ld"
)
set(PROJECT_C_FLAGS_WARNINGS "${COMMON_FLAGS_WARNINGS} ${C_FLAGS_WARNINGS_EXTRA}")
######################################################################
#
# Sources
#
######################################################################
set(PROJECT_INCLUDE_DIRS
${PROJECT_CONFIG_DIR}
${BLINK_DIR}/../
${CYPRESS_CORE_LIBRARY}
)
set(PROJECT_SRCS
${PROJECT_SOURCE_DIR}/main_cm0plus.c
${CYPRESS_PERIPHERAL_DRIVERS_LIBRARY}system_tviibe1m_cm0plus.c
${CYPRESS_PERIPHERAL_DRIVERS_LIBRARY}startup_cm0plus.S
)
######################################################################
#
# TARGET
#
######################################################################
set (CMAKE_C_FLAGS "${C_FLAGS} ${C_FLAGS_WARNINGS} ${FLAGS_OPTIMIZATION} ${PROJECT_FLAGS_ARCH}")
set (CMAKE_ASM_FLAGS "${C_FLAGS} ${C_FLAGS_WARNINGS} ${FLAGS_OPTIMIZATION} ${PROJECT_FLAGS_ARCH}")
#set (CMAKE_CXX_FLAGS "${CXX_FLAGS} ${CXX_FLAGS_WARNINGS} ${FLAGS_OPTIMIZATION} ${PROJECT_FLAGS_ARCH}")
set (CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS} ${PROJECT_LINKER_FLAGS} ${FLAGS_OPTIMIZATION} ${PROJECT_FLAGS_ARCH}")
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
include_directories(
${PROJECT_INCLUDE_DIRS}
${CYPRESS_PERIPHERAL_DRIVERS_LIBRARY_INCLUDE_DIRS}
# )
add_executable(${PROJECT_NAME}.elf ${PROJECT_SRCS} ${CYPRESS_PERIPHERAL_DRIVERS_LIBRARY_SRCS})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")

I convert to .bin and .hex it with the following command:
add_custom_command(TARGET ${APPLICATION}
POST_BUILD
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${OBJCOPY} ARGS -O binary ${APPLICATION} ${APPLICATION_BIN}
COMMAND ${OBJCOPY} ARGS -O ihex -R .eeprom -R .fuse -R .lock -R .signature ${APPLICATION} ${APPLICATION_HEX}
)
One notable difference is the ARGS as suggested here: https://stackoverflow.com/a/53573133

Related

how do you escape an nmake command line inside cmake?

I am trying to build zlib on windows as a dependency in my cmake project.
I have come up with the following which works fine:
file(WRITE ${CMAKE_BINARY_DIR}/zlib.nmake
AS=ml64\n
LOC="-DASMV -DASMINF -DNDEBUG -I."\n
OBJA="inffasx64.obj gvmat64.obj inffas8664.obj"\n
-f win32/Makefile.msc\n
zlib.lib\n)
ExternalProject_Add(
zlib
GIT_REPOSITORY https://github.com/kyotov/zlib.git
GIT_TAG mt
PREFIX ${CMAKE_BINARY_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> nmake #${CMAKE_BINARY_DIR}/zlib.nmake
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/zlib.h <INSTALL_DIR>/install/include/zlib.h
COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/zconf.h <INSTALL_DIR>/install/include/zconf.h
COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/zlib.lib <INSTALL_DIR>/install/lib/zlib.lib
COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/zlib.pdb <INSTALL_DIR>/install/lib/zlib.pdb
)
I would really prefer if I can inline the call to nmake and not have to resort to passing # parameter.
I spent about 15-30 minutes trying to escape the double quotes in various ways but could not get it done.
Google did not teach me anything either...
Anybody has any smart ideas?

CMake add_custom_command replaces slash with backslash on windows

I'm trying to create a conan-package (hint: the names contain forward-slashes) as a postbuild operation with something like this:
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
WORKING_DIRECTORY ${PROJECT_DIR}
COMMAND conan export-pkg .. "gtest/1.10.0#shared/testing" -f -pr ${CONAN_PROFILE}
COMMENT "Uploading conan package..."
)
On Linux/Ubuntu/WSL this works fine.
conan export-pkg . 'gtest/1.10.0#shared/testing' -f -pr './platforms/platform_linux-x86-clang/conan_profile/linux-x86-clang'
On Windows the executed command looks like this:
conan export-pkg . 'gtest\1.10.0#shared\testing' -f -pr .\platforms\platform_win-x86-clang\conan_profile\win-x86-clang
How do I keep cmake from replacing / with \? Is there a setting for this?
You can use the file(TO_CMAKE_PATH "<path>" <variable>) command. It force the path to have a format with / separator.
In your case you have to put gtest/1.10.0#shared/testing in a variable with the command :
file(TO_CMAKE_PATH "gtest/1.10.0#shared/testing" GTEST_PATH)
file(TO_CMAKE_PATH ${CONAN_PROFILE} CONAN_PROFILE)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
WORKING_DIRECTORY ${PROJECT_DIR}
COMMAND conan export-pkg .. ${GTEST_PATH} -f -pr ${CONAN_PROFILE}
COMMENT "Uploading conan package..."
)

Code coverage ( *.cpp.gcda: CANNOT OPEN) is not working

I want to code coverage with gcov & lcov. But I got a few error.I think My CMakeLists is not providing ".gcda" files or is not finding ".gcda" files.
I tried a lot of solutions. Such as;
- I looked at similar projects and rearranged:
For example: https://jhbell.com/using-cmake-and-gcov
- I changed object output direcory:
set(OBJECT_OUTPUT_DIR ${CMAKE_BINARY_DIR}/test/CMakeFiles/*****rpmsgtobetested.dir)
But I didn't solve this problem.
CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
option(COMPILE_TESTS "Compile the tests" OFF)
if(COMPILE_TESTS)
enable_language(C)
enable_language(CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(DEFINED ENV{CPPUTEST_HOME})
message(STATUS "Using CppUTest home: $ENV{CPPUTEST_HOME}")
set(CPPUTEST_INCLUDE_DIRS $ENV{CPPUTEST_HOME}/include)
set(CPPUTEST_LIBRARIES $ENV{CPPUTEST_HOME}/lib)
set(CPPUTEST_LDFLAGS CppUTest CppUTestExt)
else()
find_package(PkgConfig REQUIRED)
pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
endif()
pkg_check_modules(******rpmsgtest_depends json-c)
add_definitions(-DCPPUTEST_USE_MEM_LEAK_DETECTION=0)
add_definitions("-std=c++11")
# Coverage bilgisi elde etmek için CXX flagları
#
set(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE OFF)
set(OBJECT_OUTPUT_DIR ${CMAKE_BINARY_DIR}/test/CMakeFiles/******rpmsgtobetested.dir)
# (1) set sources to be tested
set(TARGET_LIBTOBETESTED ******rpmsgtobetested)
set(libtobetested_sources
../src/rpmsg_device.cpp
../src/rpmsg_sm_messages.cpp
../src/thread_interface.cpp)
add_library(${TARGET_LIBTOBETESTED} ${libtobetested_sources})
# (2) Our unit tests sources
set(TEST_APP_NAME ${TARGET_LIBTOBETESTED}_tests)
set(TEST_SOURCES
test_rpmsg_device.cpp
main.cpp
fake_sdevent.cpp
fake_syscalls.cpp
)
# (3) Take care of include directories
include_directories(${CPPUTEST_INCLUDE_DIRS}
../include
/usr/include/glib-2.0
/usr/include/gio-unix-2.0
${******rpmsgtest_depends_INCLUDE_DIRS})
link_directories(${CPPUTEST_LIBRARIES})
link_libraries(${TARGET_LIBTOBETESTED})
# (4) Build the unit tests objects and link then with the app library
add_executable(${TEST_APP_NAME} ${TEST_SOURCES})
target_compile_options(${TEST_APP_NAME} PUBLIC ${******rpmsgtest_depends_CFLAGS})
target_link_libraries(${TEST_APP_NAME} ${link_libraries}
${CPPUTEST_LDFLAGS}
${******rpmsgtest_depends_LIBRARIES}
)
# (5) Run the test once the build is done
add_custom_command(TARGET ${TEST_APP_NAME} COMMAND ./${TEST_APP_NAME} POST_BUILD)
############################################################################
################################### LCOV ###################################
############################################################################
add_custom_target(lcov
COMMAND mkdir -p coverage
COMMAND mkdir -p coverage/html
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_command(TARGET lcov
COMMAND echo "################# LCOV #################"
COMMAND lcov -c -d ${COVERAGE_DATA_DIR} -o ${CMAKE_BINARY_DIR}/coverage.info
COMMAND lcov --remove ${CMAKE_BINARY_DIR}/coverage.info '**/include/**' -o ${CMAKE_BINARY_DIR}/coverage_filtered.info
COMMAND genhtml -o ${CMAKE_BINARY_DIR}/coverage/html ${CMAKE_BINARY_DIR}/coverage_filtered.info --ignore-errors source
COMMAND echo "-- Coverage report has been output to ${CMAKE_BINARY_DIR}/coverage/html"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_dependencies(lcov ${TARGET_LIBTOBETESTED})
############################################################################
################################### GCOV ###################################
############################################################################
add_custom_target(gcov
COMMAND mkdir -p coverage
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_command(TARGET gcov
COMMAND echo "################# GCOV #################"
COMMAND gcov -b ${libtobetested_sources} -o ${OBJECT_OUTPUT_DIR} | grep -A 5 ".cpp$" > CoverageSummary.tmp
COMMAND cat CoverageSummary.tmp
COMMAND echo "-- Coverage files have been output to ${CMAKE_BINARY_DIR}/coverage"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/coverage
)
add_dependencies(gcov ${TARGET_LIBTOBETESTED})
else()
message(STATUS "Cross compile environment set")
endif()
Like below the last of my code output.
TEST(RpmsgDevice_test, create_new_object_with_null_param) - 0 ms
TEST(RpmsgDevice_test, create_new_object_cannot_open_device) - 0 ms
TEST(RpmsgDevice_test, create_new_object_with_thread) - 0 ms
OK (10 tests, 10 ran, 20 checks, 0 ignored, 0 filtered out, 0 ms)
profiling:/home/msergenergen/Desktop/*****/IP/*****-lib-rpmsg/build-test/test/CMakeFiles/*****rpmsgtobetested.dir//src/rpmsg_sm_messages.cpp.gcda:Cannot open
profiling:/home/msergenergen/Desktop/*****/IP/*****-lib-rpmsg/build-test/test/CMakeFiles/*****rpmsgtobetested.dir//src/rpmsg_device.cpp.gcda:Cannot open
profiling:/home/msergenergen/Desktop/*****/IP/*****-lib-rpmsg/build-test/test/CMakeFiles/*****rpmsgtobetested_tests.dir/fake_syscalls.cpp.gcda:Cannot open
profiling:/home/msergenergen/Desktop/*****/IP/*****-lib-rpmsg/build-test/test/CMakeFiles/*****rpmsgtobetested_tests.dir/fake_sdevent.cpp.gcda:Cannot open
profiling:/home/msergenergen/Desktop/*****/IP/******-lib-rpmsg/build-test/test/CMakeFiles/*****rpmsgtobetested_tests.dir/main.cpp.gcda:Cannot open
profiling:/home/msergenergen/Desktop/*****/IP/*****-lib-rpmsg/build-test/test/CMakeFiles/*****rpmsgtobetested_tests.dir/test_rpmsg_device.cpp.gcda:Cannot open
[100%] Built target *****rpmsgtobetested_tests

Getting libcrypto ar error while compiling OpenSSL for Mac

I have been able to compile a specific version of OpenSSL for iOS devices, and I am now trying to compile for Mac OSX. However, when I run my bash script (provided below) I am getting the following error:
ar r ../../libcrypto.a o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
ar: ../../libcrypto.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: ../../libcrypto.a: Inappropriate file type or format
When I run lipo -info libcrypto.a I get the following result:
Architectures in the fat file: libcrypto.a are: i386 x86_64
This does not make any sense, as my bash script is only configuring OpenSSL for i386 (I was looping to do both, but removed x86_64 once I started getting these problems).
I have tried following the answers for similar SO questions here and here. However, those yielded the same results. Additionally, the Mac installation instructions on the OpenSSL Wiki were of no help either.
My scripts:
Build.sh
projectDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARCHS=("i386")
FIPS_VERSION="2.0.12"
OPENSSL_VERSION="1.0.2g"
rm -rf openssl* fips*
if [ -d "out" ]; then
rm -rf out
fi
mkdir out
source ./Build-FIPS.sh
cd $projectDir
source ./Build-OpenSSL.sh
Build-OpenSSL.sh
set -e
function main() {
verifyopenssl
for ((i=0; i < ${#ARCHS[#]}; i++))
do
makeopenssl "${ARCHS[i]}"
done
}
function verifyopenssl() {
gpg --verify $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz.asc
tar -zxf $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz
cd openssl-$OPENSSL_VERSION
}
function makeopenssl() {
BUILD_ARCH=$1
SDK_NAME="macosx"
GCC=$(xcrun -sdk ${SDK_NAME} -find gcc)
SDK_PATH=$(xcrun -sdk ${SDK_NAME} --show-sdk-path)
MACHINE="darwin-i386-cc"
# BSD_ARCH="BSD-generic32"
CONFIG_ARGS="$MACHINE \
$BSD_ARCH \
--openssldir=$projectDir/out/openssl_${BUILD_ARCH} \
fips \
--with-fipsdir=${projectDir}/out/fips_${BUILD_ARCH} \
no-idea \
no-cast \
no-seed \
no-md2 \
no-sha0 \
no-whirlpool \
-DL_ENDIAN"
export CC="${GCC} -arch ${BUILD_ARCH}"
export CFLAGS="-isysroot ${SDK_PATH} -I ${projectDir}/out/fips_${BUILD_ARCH}/include"
export LDFLAGS="-arch $BUILD_ARCH"
./Configure ${CONFIG_ARGS}
make depend
make
# make install
# make clean && make dclean
}
main $#
Following #jww's answer, I found that changing the following line (around line 69) in the main Makefile (the one in the root folder) solved the ar linking problem that #jww mentioned:
AR= ar $(ARFLAGS) r to AR= libtool -o
Making this change did get me further along in the process. However, I began having other problems. Further "research" led me to the OpenSSL FAQ page which had a question talking about OpenSSL failing to build on Mac. It pointed me to the PROBLEMS file in the root directory of the OpenSSL source code. That file said that there is a MAC ld problem:
This is really a misfeature in ld, which seems to look for .dylib
libraries along the whole library path before it bothers looking for
.a libraries. This means that -L switches won't matter unless OpenSSL
is built with shared library support.
The workaround may be to change the following lines in apps/Makefile
and test/Makefile:
LIBCRYPTO=-L.. -lcrypto
LIBSSL=-L.. -lssl
to:
LIBCRYPTO=../libcrypto.a
LIBSSL=../libssl.a
With this information, I created a patch file for the root Makefile and the Makefile in the apps folder. I also found that I had to comment out the instructions in the main Makefile and the apps/Makefile to build the openssl binary / executable. This should only be necessary if you want to run make install.
The patch files exists at the same level as the Build.sh script. And after fiddling around with my Build-OpenSSL.sh script I was finally able to get it to build for both i386 and x86_64.
For future reference, I am including the complete contents of the two patch files, and the original two script files below.
Build.sh
#!/bin/bash
#
projectDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARCHS=("i386" "x86_64")
FIPS_VERSION="2.0.12"
OPENSSL_VERSION="1.0.2g"
rm -rf openssl*
if [ -d "out" ]; then
rm -rf out
fi
mkdir out
source ./Build-FIPS.sh
source ./Build-OpenSSL.sh
Build-OpenSSL.sh
#!/bin/bash
#
set -e
function main() {
verifyopenssl
for ((i=0; i < ${#ARCHS[#]}; i++))
do
makeopenssl "${ARCHS[i]}"
done
}
function verifyopenssl() {
gpg --verify $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz.asc
tar -zxf $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz
cd openssl-$OPENSSL_VERSION
}
function makeopenssl() {
BUILD_ARCH=$1
SDK_NAME="macosx"
GCC=$(xcrun -sdk ${SDK_NAME} -find gcc)
SDK_PATH=$(xcrun -sdk ${SDK_NAME} --show-sdk-path)
if [[ $BUILD_ARCH = "i386" ]]; then
MACHINE="darwin-i386-cc"
NISTP=""
elif [[ $BUILD_ARCH = "x86_64" ]]; then
MACHINE="darwin64-x86_64-cc"
NISTP="enable-ec_nistp_64_gcc_128"
else
exit
fi
CONFIG_ARGS="$MACHINE \
$NISTP \
--openssldir=$projectDir/out/openssl_${BUILD_ARCH} \
fips \
--with-fipsdir=${projectDir}/out/fips_${BUILD_ARCH} \
no-idea \
no-cast \
no-seed \
no-md2 \
no-sha0 \
no-whirlpool \
-DL_ENDIAN"
./Configure ${CONFIG_ARGS}
patch Makefile < ../MainMake.patch
patch apps/Makefile < ../AppMake.patch
make depend
make build_libcrypto build_libssl
make install_sw
make clean && make dclean
patch -R Makefile < ../MainMake.patch
patch -R apps/Makefile < ../AppMake.patch
}
main $#
AppMake.patch
--- apps/Makefile 2016-03-01 06:36:53.000000000 -0700
+++ ../Makefile 2016-05-06 13:00:16.000000000 -0600
## -26,8 +26,8 ##
DLIBCRYPTO=../libcrypto.a
DLIBSSL=../libssl.a
-LIBCRYPTO=-L.. -lcrypto
-LIBSSL=-L.. -lssl
+LIBCRYPTO=../libcrypto.a
+LIBSSL=../libssl.a
PROGRAM= openssl
## -101,24 +101,24 ##
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
install:
- #[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
- #set -e; for i in $(EXE); \
- do \
- (echo installing $$i; \
- cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
- chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
- mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
- done;
- #set -e; for i in $(SCRIPTS); \
- do \
- (echo installing $$i; \
- cp $$i $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
- chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
- mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i ); \
- done
- #cp openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
- chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
- mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
+ # #[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
+ # #set -e; for i in $(EXE); \
+ # do \
+ # (echo installing $$i; \
+ # cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+ # chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+ # mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
+ # done;
+ # #set -e; for i in $(SCRIPTS); \
+ # do \
+ # (echo installing $$i; \
+ # cp $$i $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
+ # chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
+ # mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i ); \
+ # done
+ # #cp openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
+ # chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
+ # mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
tags:
ctags $(SRC)
MainMake.patch
--- Makefile 2016-05-06 13:06:11.000000000 -0600
+++ ../Makefile 2016-05-06 13:06:44.000000000 -0600
## -602,8 +602,8 ##
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
cp libssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
- cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
- chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
+ # cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
+ # chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
install_html_docs:
here="`pwd`"; \
ar r ../../libcrypto.a o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
ar: ../../libcrypto.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: ../../libcrypto.a: Inappropriate file type or format
ar, libtool and -arch is the reason the answer says "... supplying -arch x86_64 -arch i386 will result in a build failure because of the way OpenSSL's build system forms commands" at Build Multiarch OpenSSL on OS X.
You need to use Apple's libtool, and stop using ar. Apple's libtool knows about architectures, ar does not.
Another small wrinkle is the makefile does something like this, if I recall correctly. It makes it difficult to simply use Apple's libtool, and stop using ar:
$(AR) $(ARFLAGS) $# ...
In many makefiles you can simply make AR="libtool -o", but this case is different because the command comes out libtool -o r libcrypto.a or similar. I also seem to recall something like make AR="libtool" ARFLAGS="r -o $#" does not work well either.
I used to patch the makefile after config to do it.

Use shell command as INSTALL_COMMAND to ExternalProject_Add

Is it possible to use any shell command for the INSTALL_COMMAND phase of cmake's ExternalProject_Add? e.g.
ExternalProject_Add(leveldb
GIT_REPOSITORY git#github.com:google/leveldb.git
GIT_TAG v1.18
CONFIGURE_COMMAND ./build_detect_platform build.settings .
BUILD_COMMAND make -j 8
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)
# INSTALL_COMMAND "mkdir -p ${CMAKE_BINARY_DIR}/lib/ \
# && find . \( -name \"*${CMAKE_SHARED_LIBRARY_SUFFIX}\" -or -name \"*${CMAKE_STATIC_LIBRARY_SUFFIX}\" \
# -exec cp {} ${CMAKE_BINARY_DIR}/lib/\;\) \
# && cp -r ./include ${CMAKE_BINARY_DIR}")
I commented out the INSTALL_COMMAND I want to use, find and cp don't seem to be allowed, "No such file or directory, error 127" is the result of using this.
Direct Answer:
install(CODE "execute_process(...)")
The SCRIPT and CODE signature:
install([[SCRIPT <file>] [CODE <code>]] [...])
The SCRIPT form will invoke the given CMake script files during installation. If the script file name is a relative path it will be interpreted with respect to the current source directory. The CODE form will invoke the given CMake code during installation. Code is specified as a single argument inside a double-quoted string. For example, the code
install(CODE "MESSAGE(\"Sample install message.\")")
will print a message during installation.
Food for thought:
You might be in a hurry to get something done quickly. Do consider this if you have time or you can get back to it and fix it.
One of the main reasons why people love cmake is because of it's cross platform nature. Any project when properly coded with this aspect in mind will work with either on Linux or Windows or any other operating supported system. The various generators will work happily if the developer had this in mind. My suggestion is to convert the shell commands into cmake in a cross platform way, put them in a separate *.cmake file and execute them using cmake -E option.
Here is an extract from a working project that I had worked on in the past.
project_build_steps.cmake
message(VAR1=${VAR1}) # These variables can be passed from the invocation place
message(VAR2=${VAR2}) # You can use them in the build steps
if("${BUILD_STEP}" STREQUAL "patch")
message("BUILD_STEP: patch")
# Put your patch steps using cmake
endif()
if("${BUILD_STEP}" STREQUAL "configure")
message("BUILD_STEP: configure")
# Put your configure steps using cmake
endif()
if("${BUILD_STEP}" STREQUAL "build")
message("BUILD_STEP: build")
# Put your build steps using cmake
endif()
if("${BUILD_STEP}" STREQUAL "install")
message("BUILD_STEP: install")
# Put your install steps using cmake
endif()
CMakeLists.txt (Option 1)
set(CMAKE_COMMAND /usr/bin/cmake)
set(PROJECT_BUILD_STEPS_FILE project_build_steps.cmake)
ExternalProject_Add(
project_name
SOURCE_DIR /path/to/project/source
PATCH_COMMAND ${CMAKE_COMMAND} -DBUILD_STEP=patch -P ${PROJECT_BUILD_STEPS_FILE}
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DBUILD_STEP=configure -P ${PROJECT_BUILD_STEPS_FILE}
BUILD_COMMAND ${CMAKE_COMMAND} -DBUILD_STEP=build -P ${PROJECT_BUILD_STEPS_FILE}
INSTALL_COMMAND ${CMAKE_COMMAND} -DBUILD_STEP=install -P ${PROJECT_BUILD_STEPS_FILE}
)
If you do not want to use ExternalProject_Add you can use something like following. This will also give you individual build targets like make project_patch, make project_configure, make project_build, make project_install.
CMakeLists.txt (Option 2)
set(CMAKE_COMMAND /usr/bin/cmake)
set(PROJECT_BUILD_STEPS_FILE project_build_steps.cmake)
set(STAMP_FILE_PROJECT_PATCH .project_patch_done)
add_custom_command(
OUTPUT ${STAMP_FILE_PROJECT_PATCH}
COMMAND ${CMAKE_COMMAND} -DVAR1=value1 -DSTEP=patch -P ${PROJECT_BUILD_STEPS_FILE}
COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_FILE_PROJECT_PATCH}
)
add_custom_target(project_patch DEPENDS ${STAMP_FILE_PROJECT_PATCH})
set(STAMP_FILE_PROJECT_CONFIGURE .project_configure_done)
add_custom_command(
OUTPUT ${STAMP_FILE_PROJECT_CONFIGURE}
COMMAND ${CMAKE_COMMAND} -DSTEP=configure -P ${PROJECT_BUILD_STEPS_FILE}
COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_FILE_PROJECT_CONFIGURE}
)
add_custom_target(project_configure DEPENDS project_patch ${STAMP_FILE_PROJECT_CONFIGURE})
set(STAMP_FILE_PROJECT_BUILD .project_build_done)
add_custom_command(
OUTPUT ${STAMP_FILE_PROJECT_BUILD}
COMMAND ${CMAKE_COMMAND} -DSTEP=build -P ${PROJECT_BUILD_STEPS_FILE}
COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_FILE_PROJECT_BUILD}
VERBATIM
)
add_custom_target(project_build DEPENDS project_configure ${STAMP_FILE_PROJECT_BUILD})
set(STAMP_FILE_PROJECT_INSTALL .project_install_done)
add_custom_command(
OUTPUT ${STAMP_FILE_PROJECT_INSTALL}
COMMAND ${CMAKE_COMMAND} -DSTEP=install -P ${PROJECT_INSTALL_STEPS_FILE}
COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_FILE_PROJECT_INSTALL}
VERBATIM
)
add_custom_target(project_install DEPENDS project_build ${STAMP_FILE_PROJECT_INSTALL})

Resources