Commit 774d455dc720dc0d90d4d0bbdc57bde0ccb9f51d

Authored by Kevin Brightwell
1 parent 7081d818

Update CMakeLists to be more configurable

* Add cxxopts.hpp as a source file to executable
* Add msvc options for compiling
* Add CXXOPTS_BUILD_EXAMPLES option to CMake build
  * This is helpful when using CMake's ExternalProject_add()
  * It is ON by default, but configurable from the command-line.
.gitignore
1 1 *.swp
  2 +build*
... ...
CMakeLists.txt
... ... @@ -31,6 +31,8 @@ project(cxxopts)
31 31  
32 32 set(VERSION "0.0.1")
33 33  
  34 +option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
  35 +
34 36 set(CXXOPTS_LINKER_LIBRARIES "")
35 37  
36 38 set(CXXOPTS_USE_UNICODE_HELP FALSE CACHE BOOL "Use ICU Unicode library")
... ...
src/CMakeLists.txt
... ... @@ -18,9 +18,14 @@
18 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 19 # THE SOFTWARE.
20 20  
21   -add_executable(example example.cpp)
  21 +if(CXXOPTS_BUILD_EXAMPLES)
  22 + add_executable(example example.cpp cxxopts.hpp)
22 23  
23   -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
24   -target_link_libraries(example ${CXXOPTS_LINKER_LIBRARIES})
  24 + if (MSVC)
  25 + target_compile_options(example PUBLIC /W2)
  26 + elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  27 + target_compile_options(example PUBLIC -std=c++11 -Wall)
  28 + endif()
  29 +endif()
25 30  
26 31 install(FILES cxxopts.hpp DESTINATION include)
... ...