diff --git a/.gitignore b/.gitignore index c7ea7a6..f5e7463 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,2 @@ -compile/* -CMakeCache.txt -CMakeFiles -cmake_install.cmake -Makefile -compiler -bin +build/* build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 878733b..2c0d5d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,11 @@ project(main VERSION 1.0.0 HOMEPAGE_URL "https://git.noorlander.info/E.Noorlande # Set a custom application name and definitions set(BIN_NAME "test") add_compile_definitions(APP_NAME="${BIN_NAME}") +add_compile_definitions(MESSAGE="Hello for TESTLIB from cmake.") +add_compile_definitions(MAIN_MESSAGE="Hello for main.c from cmake.") + +# set 1 to compile static (Standalone) +set(BIN_STATIC 1) # Set binary suffix based on the operating system if(CMAKE_SYSTEM_NAME STREQUAL "Windows") @@ -34,10 +39,6 @@ set(SubProjects # Create the main executable, specifying the source file add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c) -# Set some application definitions -target_compile_definitions(${PROJECT_NAME} PUBLIC MESSAGE="Hello for TESTLIB from cmake.") #TODO String don't pass to .c file -target_compile_definitions(${PROJECT_NAME} PUBLIC MAIN_MESSAGE="Hello for main.c from cmake.") #TODO String don't pass to .c file - set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${BIN_NAME} @@ -53,5 +54,9 @@ foreach(Project IN LISTS SubProjects) endif() # Link the subproject to the main project executable - target_link_libraries(${PROJECT_NAME} PRIVATE ${Project}) + if(BIN_STATIC) + target_link_libraries(${PROJECT_NAME} PRIVATE ${Project} -static) + else() + target_link_libraries(${PROJECT_NAME} PRIVATE ${Project}) + endif() endforeach() \ No newline at end of file