Multi-Architecture in CMake and Makefiles - makefile

I'm using CMake to generate solution for Visual Studio and Makefile for Windows. I have already succeeded to make different folder for debug and release types, and i found the two options in my solution.
Now i have 3 questions :
I want to do the same for win32 and x64 ? Is it possible ? EDIT : After some research, it's seem not possible ?)
And the another question, when i generate "NMake Makefiles" i can't retrieve my two types (release and debug) in my makefile ! In which files i can retrieve this ?
EDIT : And how can i set debug or release in CLI with NMake command ?
Here is my CMakeLists.txt :
cmake_minimum_required(VERSION 2.8)
# Configuration of Types
MESSAGE("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
#Configuration of zlib.lib
PROJECT(zlib C)
# Path of Release
SET(LIB_RELEASE_PATH "../cmake_x64")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${LIB_RELEASE_PATH}/lib/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${LIB_RELEASE_PATH}/lib/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${LIB_RELEASE_PATH}/lib/" )
# Path of Debug
SET(LIB_DEBUG_PATH "../cmake_x64d")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${LIB_DEBUG_PATH}/lib/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${LIB_DEBUG_PATH}/lib/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${LIB_DEBUG_PATH}/lib/" )
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3")
ADD_DEFINITIONS("/Gm" -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_UNICODE)
# Files of librairy
ADD_LIBRARY(
zlib
STATIC
../.c
and
../.h
)
#Configuration of core.dll
project(core CXX)
# Path of Release
SET(BIN_RELEASE_PATH "../cmake_x64")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
# Path of Debug
SET(BIN_DEBUG_PATH "../cmake_x64d")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
set_property(GLOBAL PROPERTY LINK_LIBRARY_DEPENDENCIES "yes")
add_definitions(-D_UNICODE -D_USRDLL -DCORE_EXPORTS)
add_definitions("/Gm")
# Files of librairy
add_library(
core
SHARED
../.h
and
../.cpp
)
link_directories("/build/lib/")
target_link_libraries(core zlib)
#END OF FILE
Thanks

I don't know much about nmake or the cmake nmake generator, but if it's anything like the makefile generator then the answer to all three of your questions is "you can't".
For the first question, Visual Studio (to my understanding) doesn't support multiple architectures the way it supports build types; certainly the cmake-generated Visual Studio project files cannot do it.
For the second question, makefiles generated by cmake do not support build types, and I'm assuming nmake has the same limitation. I expect this is just a limitation in the cmake makefile generator; there's no inherent reason in makefiles that multiple build types couldn't be supported.
And similarly for the third question, since you cannot support multiple build types with makefile/nmake output you certainly cannot choose which one to build on the command line.
The answer to all these questions is, you have to re-run cmake with different flags to select different options (architecture and build type).
If what you're concerned about is not having to clean your workspace and reconfigure it from scratch each time and lose your previous work, then you should look into the out-of-source build feature of cmake. Basically, instead of using:
cmake .
you use something like:
mkdir obj-x86
cd obj-x86
cmake ..
mkdir ..\obj-x64
cd ..\obj-x64
cmake ..
You run cmake in a different directory (doesn't have to be a subdirectory) for each different configuration. They can all share the same source tree. Sometimes when you try this for the first time you'll discover issues in your cmake files where they're assuming a particular working directory, etc., and you may need to update them to use variables like CMAKE_SOURCE_DIR rather than relative paths.

Related

How to Define Output Directory of Coverage Files in CMake

I am trying to make a very simple regression model that (among other things), builds and compiles a GCC target for coverage, executes, and then publishes a standard Cobertura coverage report (all within Jenkins). The Jenkins part is somewhat irrelevant here, I'm only concerned with CMake syntax at the moment. This is my CMake file so far:
cmake_minimum_required( VERSION 3.15 )
# Project's name
project( my_project )
# Set the output folder where your program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/test/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set( CMAKE_VERBOSE_MAKEFILE on )
# Generate coverage on GCC.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(LDFLAGS "${LDFLAGS} -lgcov -fprofile-arcs")
endif()
# Includes and Sources
include_directories(${PROJECT_SOURCE_DIR}/inc)
file(GLOB APP_SRC "./src/*.c")
file(GLOB TEST_DEPENDS_SRC "./test/src/*.c")
# Add executable to list.
add_executable( ${PROJECT_NAME}_Test ${APP_SRC} ${TEST_DEPENDS_SRC} )
This generates my *.gcno and *.gcda files in the directory /test/build/gcc/CMakeFiles/my_project.dir/*, but for ease of post-processing, I think I want these files placed alongside their source. Is that possible? If so, how? Is that best practice? I'm still pretty green when it comes to CMake.

How to add in a CMake project a global file extension (*.pde) to GCC which is treated like C++ code

I have a very simple CMake script. Unfortunately, the project uses a *.pde file which is plain C++ or C code.
CMake is working with any file ending, but I get a compiler error, because GCC does not know how to handle it. How can I add a global file extension to GCC, so that the *.pde file is compiled as a usual *.cpp file?
The -x c++ foo.pde command is nice if I want to use the console, but for CMake it is (I think) not applicable.
cmake_minimum_required(VERSION 2.8)
project(RPiCopter)
SET( RPiCopter
absdevice
containers
device
exceptions
navigation
frame
vehicle
receiver
scheduler
tinycopter.pde
)
message( STATUS "Include ArduPilot library directories" )
foreach( DIR ${AP_List} ${AP_List_Linux} ${AP_Headers} )
include_directories( "../libraries/${DIR}" )
endforeach()
include_directories( zserge-jsmn )
# ***************************************
# Build the firmware
# ***************************************
add_subdirectory ( zserge-jsmn )
#set(CMAKE_CXX_FLAGS "-x c++ *.pde")
ADD_EXECUTABLE ( RPiCopter ${RPiCopter} )
target_link_libraries ( RPiCopter -Wl,--start-group ${AP_List} ${AP_List_Linux} jsmn -Wl,--end-group )
You should be able to use set_source_files_properties along with the LANGUAGE property to mark the file(s) as C++ sources:
set_source_files_properties(${TheFiles} PROPERTIES LANGUAGE CXX)
As #steveire pointed out in his own answer, this bug will require something like the following workaround:
set_source_files_properties(${TheFiles} PROPERTIES LANGUAGE CXX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_definitions("-x c++")
endif()
Normally you should be able to just extend CMAKE_CXX_SOURCE_FILE_EXTENSIONS. This would help, if you have a lot of files with unknown file extensions.
But this variable is not cached - as e.g. CMAKE_CXX_FLAGS is - so the following code in CMakeCXXCompiler.cmake.in will always overwrite/hide whatever you will set:
set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC)
set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;mm;CPP)
I consider this non-caching being a bug in CMake, but until this is going to be changed I searched for a workaround considering the following:
You normally don't want to change files in your CMake's installation
It won't have any effect if you change CMAKE_CXX_SOURCE_FILE_EXTENSIONS after project()/enable_language() (as discussed here).
I have successfully tested the following using one of the "hooks"/configuration variables inside CMakeCXXCompiler.cmake.in:
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_SYSROOT_FLAG_CODE "list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS pde)")
project(RPiCopter CXX)
message("CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${CMAKE_CXX_SOURCE_FILE_EXTENSIONS}")
add_executable(RPiCopter tinycopter.pde)
I decided to use this approach. I just remove the file ending by cmake in the temporary build directory.
So GCC is not confused anymore because of the strange Arduino *.pde file extension.
# Exchange the file ending of the Arduino project file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tinycopter.pde ${CMAKE_CURRENT_BINARY_DIR}/tinycopter.cpp)
CMake doesn't do this for you:
http://public.kitware.com/Bug/view.php?id=14516

Why solution generate by CMake not output the same files size than Visual

I've generate a solution for Visual Studio with CMake. It compile fines like the original solution. But when i look at my output folder, the files are not the same size as those generated by the initial solution.
Example :
DLL generate by initial solution :
core.dll - 767ko
The same DLL generate by the solution of CMake :
core.dll - 669Ko
And the same thing appears for a .lib :
zlib.lib - 305 Ko (for the initial solution)
zlib.lib - 242 Ko (for the CMake solution)
But I use Visual Studio 2013 for two... And the types are the same : Debug / Win32. I verify all the Flags multiple time, but anyway it still generate different size files.
EDIT : I add my CMakeLists
cmake_minimum_required(VERSION 2.8)
# Configuration of Types
MESSAGE("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
#SET(CMAKE_CACHEFILE_DIR ${BUILD_PATH})
#Configuration of zlib.lib
PROJECT(zlib C)
# Path of Release
SET(LIB_RELEASE_PATH "../build/cmake_x64")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${LIB_RELEASE_PATH}/lib/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${LIB_RELEASE_PATH}/lib/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${LIB_RELEASE_PATH}/lib/" )
# Path of Debug
SET(LIB_DEBUG_PATH "../build/cmake_x64d")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${LIB_DEBUG_PATH}/lib/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${LIB_DEBUG_PATH}/lib/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${LIB_DEBUG_PATH}/lib/" )
#Flags
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /D_UNICODE")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /Oi /Gy /GR- /Gm-")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Gm /Ob0- /GR- /Gm")
# Files of librairy
ADD_LIBRARY(
zlib
STATIC
../.c
and
../.h
)
#Configuration of core.dll
project(core CXX)
# Path of Release
SET(BIN_RELEASE_PATH "../build/cmake_x64")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
# Path of Debug
SET(BIN_DEBUG_PATH "../build/cmake_x64d")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
# Flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /D_UNICODE /D_USRDLL /DCORE_EXPORTS /DUNICODE")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /GL /Oi /Gy /DEBUG /INCREMENTAL:NO /GR- /Gm-")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Gm /GR-")
# Files of librairy
add_library(
core
SHARED
../.h
and
../.cpp
)
target_link_libraries(core zlib)
SET_PROPERTY(TARGET core APPEND PROPERTY LINK_FLAGS /DEBUG)
#END OF FILE
And here is my Ouput from Command Line :
Generated with config types:
-- The C compiler identification is MSVC 18.0.21005.1
-- Check for working C compiler using: Visual Studio 12 2013
-- Check for working C compiler using: Visual Studio 12 2013 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- The CXX compiler identification is MSVC 18.0.21005.1
CMake Warning (dev) at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/CMak
eDetermineCXXCompiler.cmake:106 (if):
Policy CMP0054 is not set: Only interpret if() arguments as variables or
keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
Quoted variables like "MSVC" will no longer be dereferenced when the policy
is set to NEW. Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
CMakeLists.txt:61 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/CMak
eFindBinUtils.cmake:33 (if):
Policy CMP0054 is not set: Only interpret if() arguments as variables or
keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
Quoted variables like "MSVC" will no longer be dereferenced when the policy
is set to NEW. Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/CMakeDetermineCXXCompiler
.cmake:162 (include)
CMakeLists.txt:61 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Check for working CXX compiler using: Visual Studio 12 2013
-- Check for working CXX compiler using: Visual Studio 12 2013 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/mea/Documents/developpement/Repos/
corealpi2/cmake/build
Does anyone have an idea what might cause this?
Thanks

cmake find sqlite3 library on windows

I am having more trouble than I'd expect getting CMake to find the sqlite3.dll library on Windows 7 (64-bit if that matters). I have downloaded and placed the latest sqlite3.dll and sqlite3.def files to C:\Windows\System32. I am using the FindSqlite3.cmake module below:
IF( SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY_RELEASE AND SQLITE3_LIBRARY_DEBUG )
SET(SQLITE3_FIND_QUIETLY TRUE)
ENDIF( SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY_RELEASE AND SQLITE3_LIBRARY_DEBUG )
FIND_PATH( SQLITE3_INCLUDE_DIR sqlite3.h )
FIND_LIBRARY(SQLITE3_LIBRARY_RELEASE NAMES sqlite3 )
FIND_LIBRARY(SQLITE3_LIBRARY_DEBUG NAMES sqlite3 sqlite3d HINTS /usr/lib/debug/usr/lib/ C:/Windows/System32/ )
IF( SQLITE3_LIBRARY_RELEASE OR SQLITE3_LIBRARY_DEBUG AND SQLITE3_INCLUDE_DIR )
SET( SQLITE3_FOUND TRUE )
ENDIF( SQLITE3_LIBRARY_RELEASE OR SQLITE3_LIBRARY_DEBUG AND SQLITE3_INCLUDE_DIR )
IF( SQLITE3_LIBRARY_DEBUG AND SQLITE3_LIBRARY_RELEASE )
# if the generator supports configuration types then set
# optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
IF( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
SET( SQLITE3_LIBRARIES optimized ${SQLITE3_LIBRARY_RELEASE} debug ${SQLITE3_LIBRARY_DEBUG} )
ELSE( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
# if there are no configuration types and CMAKE_BUILD_TYPE has no value
# then just use the release libraries
SET( SQLITE3_LIBRARIES ${SQLITE3_LIBRARY_RELEASE} )
ENDIF( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
ELSEIF( SQLITE3_LIBRARY_RELEASE )
SET( SQLITE3_LIBRARIES ${SQLITE3_LIBRARY_RELEASE} )
ELSE( SQLITE3_LIBRARY_DEBUG AND SQLITE3_LIBRARY_RELEASE )
SET( SQLITE3_LIBRARIES ${SQLITE3_LIBRARY_DEBUG} )
ENDIF( SQLITE3_LIBRARY_DEBUG AND SQLITE3_LIBRARY_RELEASE )
IF( SQLITE3_FOUND )
IF( NOT SQLITE3_FIND_QUIETLY )
MESSAGE( STATUS "Found Sqlite3 header file in ${SQLITE3_INCLUDE_DIR}")
MESSAGE( STATUS "Found Sqlite3 libraries: ${SQLITE3_LIBRARIES}")
ENDIF( NOT SQLITE3_FIND_QUIETLY )
ELSE(SQLITE3_FOUND)
IF( SQLITE3_FIND_REQUIRED)
MESSAGE( FATAL_ERROR "Could not find Sqlite3" )
ELSE( SQLITE3_FIND_REQUIRED)
MESSAGE( STATUS "Optional package Sqlite3 was not found" )
ENDIF( SQLITE3_FIND_REQUIRED)
ENDIF(SQLITE3_FOUND)
This works fine on Linux, but not on Windows. I have spent a few hours now attempting small changes to other CMAKE variables with no luck. It seems like it should be straight forward getting CMake to find this dll. Could I get some help getting this to find the sqlite3 library on Windows?
There are some issues here and also some weird Windows stuff!
First issue; when searching for a library on Windows with MSVC as the generator, CMake will always look for a ".lib" file - never a ".dll", even if you specify e.g. sqlite3.dll as the NAMES argument to find_library. This is unfortunately not properly documented, in fact the docs for CMAKE_FIND_LIBRARY_SUFFIXES wrongly state:
This specifies what suffixes to add to library names when the find_library command looks for libraries. On Windows systems this is typically .lib and .dll, meaning that when trying to find the foo library it will look for foo.dll etc.
You can easily check this; simply add
message("CMAKE_FIND_LIBRARY_SUFFIXES: ${CMAKE_FIND_LIBRARY_SUFFIXES}")
to your CMakeLists.txt. You should see output like:
CMAKE_FIND_LIBRARY_SUFFIXES: .lib
This thread from the CMake mailing list further confirms this behaviour. If you really need to find the dlls, you'll need to use the find_file command, e.g:
find_file(SQLITE3_DLL_DEBUG NAMES sqlite3d.dll PATHS ...)
The next issue is a minor one. You should prefer PATHS to HINTS as the argument in find_xxx commands if it's a hard-coded guess. From the docs for find_library:
3. Search the paths specified by the HINTS option. These should be paths computed by system introspection, such as a hint provided by the location of another item already found. Hard-coded guesses should be specified with the PATHS option.
A slightly more serious issue is in the line:
FIND_LIBRARY(SQLITE3_LIBRARY_DEBUG NAMES sqlite3 sqlite3d ...)
You should specify sqlite3d first then sqlite3 or sqlite3 will incorrectly be chosen as the Debug library if both are available.
And now the weirdness...
On a Windows x64 system, the find_xxx partially ignores the C:\Windows\System32 directory in favour of the C:\Windows\SysWOW64 one.
If you don't have the sqlite3.lib in C:\Windows\SysWOW64, then the find_library command will always fail, regardless of the PATHS argument.
However, if you do have C:\Windows\SysWOW64\sqlite3.lib, then any combination of C:/Windows/SysWOW64 and/or C:/Windows/System32 as the PATHS argument finds the library, but sets the full path to C:/Windows/System32/sqlite3.lib even if C:/Windows/System32/sqlite3.lib doesn't exist! This is obviously useless if the library isn't there; a linker error will result.
There is some further reading again from the CMake mailing list here.
Having said that, if you're linking, you'll be using the .lib files, not the .dlls, and System32 & SysWOW64 aren't really the place for .lib files.
I didn't find that cmake looks for .lib. pls.
please check the cmake file and findSqlite.cmake file inside cmake folder and check for paths it is looking for.
when I gave the full path to the "dll", it worked for me corresponding to the input variable mentioned in cmake file, and it might work for you too.
If your problem is not solved, notify me to edit the answer.

CMake and Boost

I've searched and found out that a lot of people have the same problem, but no solution exists.
I'm using CMake to generate Makefiles for MinGW and when compiling I'm getting an error:
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x5e): undefined reference to `_imp___ZN5boost6thread4joinEv'
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x71): undefined reference to `_imp___ZN5boost6threadD1Ev'
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x88): undefined reference to `_imp___ZN5boost6threadD1Ev'
This seems to be a linking problem, I get it. My CMake configuration is:
project(boosttest)
cmake_minimum_required(VERSION 2.6)
include_directories(${boosttest_SOURCE_DIR}/include c:/boost_1_48_0/)
link_directories(c:/boost_1_48_0/lib)
file(GLOB_RECURSE cppFiles src/*.cpp)
add_executable(boosttest ${cppFiles})
target_link_libraries(boosttest libboost_thread-mgw46-mt-1_48.a)
First I tried using find_package(Boost COMPONENTS thread) and it was working the same way, so I thought to try to do this manually and I still get the same error.
Any insights on this?
I've compiled it for mingw using bjam and as a static link. Also tried doing:
add_library(imp_libboost_thread STATIC IMPORTED)
set_property(TARGET imp_libboost_thread PROPERTY IMPORTED_LOCATION c:/boost_1_48_0/lib/libboost_thread-mgw46-mt-1_48.a)
target_link_libraries(boosttest imp_libboost_thread)
And I still get the same error messages.
For mingw32 you may add definition BOOST_THREAD_USE_LIB. And linking with boost::thread will work. Also you may need Threads package (but i'm not sure, may be it needs only for *nix platforms).
Here is part of my CMakeLists. I copied it from project, which uses boost::thread, and compiles under mingw-gcc (and other compilers):
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0")
find_package(Boost COMPONENTS thread date_time program_options filesystem system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
find_package(Threads REQUIRED)
#...
if (WIN32 AND __COMPILER_GNU)
# mingw-gcc fails to link boost::thread
add_definitions(-DBOOST_THREAD_USE_LIB)
endif (WIN32 AND __COMPILER_GNU)
#...
target_link_libraries(my_exe
${CMAKE_THREAD_LIBS_INIT}
#...
${Boost_LIBRARIES}
)
In my opinion, this question is similar to this question and this one. My best guess would be that you need the same resolution as in my answer to the first question.
I would strongly recommend the use of find_package (Boost ) and take care with the auto-linking:
project(boosttest)
cmake_minimum_required(VERSION 2.6)
# Play with the following defines
# Disable auto-linking.
add_definition( -DBOOST_ALL_NO_LIB )
# In case of a Shared Boost install (dlls), you should then enable this
# add_definitions( -DBOOST_ALL_DYN_LINK )
# Explicitly tell find-package to search for Static Boost libs (if needed)
set( Boost_USE_STATIC_LIBS ON )
find_package( Boost REQUIRED COMPONENTS thread )
include_directories( ${Boost_INCLUDE_DIRS} )
file(GLOB_RECURSE cppFiles src/*.cpp)
add_executable(boosttest ${cppFiles})
target_link_libraries(boosttest ${Boost_LIBRARIES} )

Resources