[CMake] problem creating a library on mac

Marie-Christine Vallet mmvallet at ucdavis.edu
Thu Sep 27 18:50:20 EDT 2007


Mike Jackson wrote:
> Comments are in-line. (Note, this is one particular style of using 
> CMake, other variations are perfectly valid)
>
> --Mike Jackson   Senior Research Engineer
> Innovative Management & Technology Services
>
>
> On Sep 27, 2007, at 2:50 PM, Marie-Christine Vallet wrote:
>
>>
>> Hi,
>>         I have a project which in which I create a library and then I 
>> use
>> this library with my executable. The way I set it up seem to be 
>> working on
>> linux (fedora) but it does not work on mac ox10.
>> Could someone tell me what I am doing wrong,
>> Thanks,
>> Marie
>>
>> Project tree
>>
>> *Projectdir
>>  **mdi
>>  **skinmesh
>>
>> in my project directory I have the following cmake file :
>>
>> --------------
>> project(mdi C Fortran CXX)
>>
>>
>> cmake_minimum_required(VERSION 2.4.0)
>
> # Set a variable to point to our top level project directory
> SET (MDI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
>
>>
>>
>> SET(PROJECT_BINARY_DIR
>> ${CMAKE_SOURCE_DIR}/bin)
>>
>> SET(LIBRARY_OUTPUT_PATH
>> ${CMAKE_SOURCE_DIR}/lib)
>
> # Add some include paths to the subdirectories
> INCLUDE_DIRECTORIES ( ${MDI_SOURCE_DIR}/mdi
>                     ${MDI_SOURCE_DIR}/skinmesh  )
>
>>
>> # tell cmake to process CMakeLists.txt in these subdirectory
>> #they have to be added separately for it to work
>> #this subdirectory will create a lib so I put the lib in the lib folder
>> add_subdirectory(
>>     skinmesh
>> ${PROJECT_BINARY_DIR}
>>     )
>
> add_subdirectory( skinmesh  ${PROJECT_BINARY_DIR}/skinmesh )
> add_subdirectory( mdi  ${PROJECT_BINARY_DIR}/mdi )
>
>>
>>
>> #this add the executable in the bin directory
>> add_subdirectory (
>>         mdi
>> ${PROJECT_BINARY_DIR}
>>         )
>>
>> --------------
>>
>> In the mdi directory I have the following cmake file (part of it 
>> anyay) :
>>
>>
>> --------------
>>
>> [..]
>>
>>
>> SET(SKINMESH_LIBRARIES
>> ${LIBRARY_OUTPUT_PATH}/libskinmesh.a
>> )
>
> This is NOT needed because CMake will "know" about the library 
> libSkinMesh.a
>
>> SET(SKINMESH_INCLUDE_DIR
>> ${CMAKE_SOURCE_DIR}/skinmesh
>> )
>
> This was taken care of in the top level CMakeLists.txt file and is NOT 
> needed
>
>> SET(INCLUDE_DIR
>>         ${INCLUDE_DIR}
>> ${SKINMESH_INCLUDE_DIR}
>>
>> )
>
>  NOT NEEDED...
>
>> SET(LIBRARIES
>>          ${LIBRARIES}
>>     ${SKINMESH_LIBRARIES})
>>
>>
> NOT needed. Use the name of the library directly in the 
> TARGET_LINK_LIBRARIES function:
>  SET (SKINMESH_LIB_NAME "skinmesh" )
>
>
>
>
>> [..]
>>
>> # Mac configuration
>>  IF ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
>>
>>     
>>         #setting flags
>>         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -mp1 -Kc++ -Dintel")
>>         SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -mp1 -Kc++ -Dintel")
>>
>>                    #equivalent to ldflag
>>         SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} 
>> -bind_at_load")
>>
>> ENDIF ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
>>
>>
>> #VARIABLE INITIALISATION
>>
>> # set source files
>>
>> [..]
>>
>> SET(mdi_EXECUTABLE
>>                  ${mdi_SRCS}
>>                  ${mdi_UIS_H}
>>                  ${mdi_MOC_SRCS}
>>                  ${mdi_RCC_SRCS}
>> )
>
>
> This....
>> INCLUDE_DIRECTORIES(${INCLUDE_DIR})
>>  link_directories (${PROJECT_BINARY_DIR}/skinmesh)
>
> CMAKE will KNOW where to look for the library. Not needed.
>
>
>>
>> # create an executable file named "mdi" from the source files in the
>> variable "mdi_SRCS".
>>
>> ADD_EXECUTABLE ( mdi ${mdi_EXECUTABLE} )
>>
>>
>> TARGET_LINK_LIBRARIES ( mdi
>>                         ${LIBRARIES}
>>                       )
>>
>
> TARGET_LINK_LIBRARIES (mdi ${SKINMESH_LIB_NAME})
>
>>
>> -------------
>> In the skinmesh directory I have the following cmake file (part of it 
>> anyay) :
>>
>> -------------
>> # create an executable file named "skinmesh" from the source files in 
>> the
>> variable "skinmesh_SRCS".
>> ADD_LIBRARY ( skinmesh STATIC
>>                  ${skinmesh_SRCS}
>>                )
>>
>> #set the linker language
>> SET_TARGET_PROPERTIES(skinmesh
>>     PROPERTIES
>>     LINKER_LANGUAGE CXX
>>     )
>>
>> [..]
>>
>>
>> # Mac configuration
>>  IF ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
>>
>>         #setting flags
>>         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -c -O3 -mp1 -Kc++ -Dintel")
>>         SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c -O3 -mp1 -Kc++ 
>> -Dintel")
>>         SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -c -u -O3 
>> -mp1 -w90 -w95
>> -cpp ")
>>
>> #equivalent to ldflag
>>         SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O3 
>> -Kc++ -mp1
>> -bind_at_load")
>>
>> ENDIF ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
>>
>
> This...
>>  INCLUDE_DIRECTORIES (${INCLUDE_DIR})
>
> Most likely not needed because we set the include directories in the 
> top level CMakeLists.txt file
>
>>
>> TARGET_LINK_LIBRARIES (skinmesh
>>         ${PROJECT_LIBRARIES}
>>     )
>
> I will assume that PROJECT_LIBRARIES was set somewhere above and has 
> all your 3rd party libraries that you need listed.
>
> hope some of this helps.
>



More information about the CMake mailing list